package Thread.Demo16Pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author wangzhipeng
 * @Date 2020-08-30 5:00 下午
 * @Description 测试线程池
 *
 *
 *
 */
public class TestPool {
    public static void main(String[] args) {
        //1 创建服务，创建线程池
        //newFixedThreadPool 参数为：线程池的大小
        ExecutorService service = Executors.newFixedThreadPool(10);
        //void execute(Runnable command) : 执行任务/命令 没有返回值 一半用来执行Runnable
        service.execute(new MyThread());
        service.execute(new MyThread());
        service.execute(new MyThread());
        service.execute(new MyThread());


        //void shutdown()关闭线程池

        //2 关闭连接
        service.shutdown();


    }
}
class MyThread implements Runnable{
    @Override
    public void run() {
            System.out.println(Thread.currentThread().getName());
    }
}

